package cn.topevery.garden.dal.logic;

import cn.topevery.garden.dal.dao.ProcessLogFileDao;
import cn.topevery.garden.entity.po.ProcessLogFile;
import cn.topevery.garden.entity.query.ProcessLogFileQuery;
import cn.topevery.garden.entity.vo.ProcessLogFileVO;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 过程日志 附件表
 *
 * @author code-generate
 * @date 2022-02-17
 */
@Service
public class ProcessLogFileLogic extends BaseLogic<ProcessLogFile> {
    @Autowired
    ProcessLogFileDao processLogFileDao;

    @Override
    public BaseEntityDao<ProcessLogFile, Integer> getDao() {
        return processLogFileDao;
    }

    

    /**
     * 获取列表
     *
     * @param query
     */
    public DataPager<ProcessLogFileVO> listPage(ProcessLogFileQuery query) {
        return processLogFileDao.listPage(query);
    }

    /**
     * 根据自增id批量删除
     *
     * @param ids
     */
    public void deleteBatchById(String userId,Integer[] ids) {
        processLogFileDao.delete(userId, ids);
    }

    /**
     * 根据自增id保存或者更新
     *
     * @param processLogFile 实体
     */
    public void saveOrUpdate(String userId, ProcessLogFile processLogFile){
        processLogFileDao.saveOrUpdate(userId,processLogFile);
    }

    /**
         * 根据自定义列值来获取对象
         */
    public ProcessLogFile getEntityByColumn(String key, String value) {
        return processLogFileDao.getEntityByColumn(key, value);
    }

    public List<ProcessLogFile> getListByMainId(Integer mainId) {
        return processLogFileDao.getListByMainId(mainId);
    }

    public void saveOrUpdate(String userId, Integer mainId, List<ProcessLogFile> fileList) {
        processLogFileDao.deleteByMainId(mainId);
        for (ProcessLogFile processLogFile : fileList) {
            processLogFile.setMainId(mainId);
            processLogFileDao.saveOrUpdate(userId, processLogFile);
        }
    }

    public void deleteByMainIds(Integer[] mainIds) {
        processLogFileDao.deleteByMainIds(mainIds);
    }
}
